/*
 注册页面主要的几个功能
 	a: other 的点击向上
 	b: 吸顶菜单的制作
 	c: 注册的时候各种检验
 */
$("#username").focus();

$(".topimg").click(function() {
	scrollTo(0, 0);
})
var top_bar = document.getElementsByClassName("top-bar")[0];
var logo_nav = document.getElementsByClassName("logo-nav")[0];
var h = top_bar.clientHeight;
var o = document.getElementsByClassName("o")[0];
var other = document.getElementsByClassName("other")[0];
window.onscroll = function() {
	var jl = document.documentElement.scrollTop || document.body.scrollTop;

	if(jl >= 10) {
		o.style.position = "fixed";
		o.style.top = 0;
		other.style.display = "block"
	} else {
		o.style.position = "static";
		other.style.display = "none"
	}
}
 
$(".yanzhengma").html(getNum());
//随机生成验证码
$(".yanzhengma").click(function(){
	var num = getNum();
	$(this).html(num);
})

//获取四位数字的随机数
function getNum(){
	var t = Math.ceil(Math.random()*10*1000);
	return t;
}

/**
 	注册的条件
 **/
var cuowu = "必填";
//手机号码验证
$("#username").blur(function(){
	var reg = /^1(3|4|5|7|8)\d{9}$/;
	/*var reg1 =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;*/
	var txt = $(this).val();
	
	var cuo = "手机号码";
	if(txt.length == 0){
		$("#username-error").html(cuowu);
	}else if(!reg.test(txt)){
		$("#username-error").html(cuo);
	}else{
		$("#username-error").html("ok");
	}
})

//验证码效验
$("#yanzheng").blur(function(){
	var yan_value = $(this).val();
	var num_value = $(this).next().next().html();
	var cuo = "验证码不一致";
	if(num_value == yan_value){
		$("#yanzheng-error").html("ok");
	}else if(yan_value.length==0){
		$("#yanzheng-error").html(cuowu);
	}else{
		$("#yanzheng-error").html(cuo);
	}
})

//密码效验
 $("#pwd").blur(function(){
 	var pwdValue = $(this).val();
 	var cuo = "密码长度为6~20位"
 	if(pwdValue.length >5 && pwdValue.length<21){
 		$("#pwd-error").html("ok");
 	}else if(pwdValue.length == 0){
 		$("#pwd-error").html(cuowu);
 	}else{
 		$("#pwd-error").html(cuo);
 	}
 })
//再次确认效验
 $("#pwds").blur(function(){
 	var cuo = "密码不一致"
 	var pwdsValue = $(this).val();
 	var pwdValue = $("#pwd").val();
 	
 	if(pwdsValue.length ==0){
 		$("#pwds-error").html(cuowu);
 	}else if(pwdsValue != pwdValue){
 		$("#pwds-error").html(cuo);
 	}else{
 		$("#pwds-error").html("ok");
 	}
 })
 
$(".btn").click(function(){
	if($("#username").val() == null){
		$("#username-error").html(cuowu);
	}else if($("#pwd").val() == null){
		$("#pwd-error").html(cuowu);
	}else if($("#pwds").val() == null){
		$("#pwds-error").html(cuowu);
	}else if($("#yanzheng").val()==null){
		$("#yanzheng-error").html(cuowu);
	}else if($("#pwds-error").html()=="ok"&&$("#pwd-error").html()=="ok"&&$("#yanzheng-error").html()=="ok"&&$("#username-error").html()=="ok"){
		var uValue = $("#username").val();
		var pValue = $("#pwds").val();
//		var str=$.cookie("allyonghu");
//		if(!str){
//			$.cookie("allyonghu","[]",{expires:7,path: '/' });
//		}
//		
		$.cookie('uName',uValue,{expires:7,path: '/' });
		$.cookie('uPwd',pValue,{expires:7,path: '/' });
		alert("注册成功");
		location.href="indexs.html";
//		var arr=JSON.parse($.cookie("allyonghu"));
//		arr.push({
//		"uName":uValue	
//		});
//		$.cookie("allyonghu",JSON.stringify(arr),{expires:7,path: '/' })
	}else{
		alert("信息有错误");
	}
	
	
})
